package com.example.servicetest

import android.graphics.Color
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.LinearLayoutCompat
import androidx.databinding.DataBindingUtil
import com.example.servicetest.MyTextUtils.mLinearGradientColors
import com.example.servicetest.databinding.ActivitySecondBinding
import com.example.servicetest.util.ColorUtil

class SecondActivity : AppCompatActivity() {

    lateinit var binding: ActivitySecondBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this,R.layout.activity_second)
//        binding.ruler.setScope(5000,15001,500);
//        binding.ruler.setCurrentItem("10000");
    }

    fun doClick(view: View) {
        when(view.id){

            R.id.button->{
                binding.textPixelsCanvas.setBgLinearGradientColors(MyTextUtils.mColors4, orientation = LinearLayoutCompat.HORIZONTAL)
            }

            R.id.button_1->{
                binding.textPixelsCanvas.setBgSingleColor(Color.parseColor(ColorUtil.ranDomColor))
            }

            R.id.button1->{
                val i = (Math.random() * 2 + 1).toInt()
                val j: Int = if (i == 1) {
                    (Math.random() * 26 + 65).toInt()
                } else {
                    (Math.random() * 26 + 97).toInt()
                }
                binding.textPixelsCanvas.addNewCharacter((j.toChar()).toString())
            }

            R.id.button2->{
                binding.textPixelsCanvas.deleteLastCharacter()
            }

            R.id.button3->{
                binding.textPixelsCanvas.setTextColor(Color.parseColor(ColorUtil.ranDomColor))
            }

            R.id.button4->{
                val randoms = (0..5).random()
                val orientation =  if(randoms%2==0) LinearLayoutCompat.HORIZONTAL else LinearLayoutCompat.VERTICAL
                binding.textPixelsCanvas.setTextLinearGradientColors(mLinearGradientColors[randoms],orientation)
            }

            R.id.button5->{
                binding.textPixelsCanvas.leftMode()
            }
            R.id.button6->{
                binding.textPixelsCanvas.rightMode()
            }

            R.id.button7->{
                binding.textPixelsCanvas.flashMode()
            }
            R.id.button8->{
                binding.textPixelsCanvas.normalizationMode()
            }
        }
    }

}